import 'package:shared_preferences/shared_preferences.dart';

class LocalStorage {
  static SharedPreferences? shared;

  final String key;

  const LocalStorage({required this.key});

  initShared() async {
    shared = await SharedPreferences.getInstance();
  }

  Future<bool> setString(String key, String value) async {
    if (shared == null) {
      await initShared();
    }
    return shared!.setString('${this.key}_$key', value);
  }

  Future<String?> getString(String key) async {
    if (shared == null) {
      await initShared();
    }
    return shared!.getString('${this.key}_$key');
  }

  Future<String?> getObject(String key) async {
    if (shared == null) {
      await initShared();
    }
    return shared!.getString('${this.key}_$key');
  }

  Future<SharedPreferences> getShared() async {
    if (shared == null) {
      await initShared();
    }
    return shared!;
  }

  Future<bool> remove(String key) async {
    if (shared == null) {
      await initShared();
    }
    return shared!.remove('${this.key}_$key');
  }
}
